package net.wanglu.www.zzz.service.se.rcmod;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import net.wanglu.www.zzz.service._Service;
import net.wanglu.www.zzz.service.se.__SentenceElements;
import edu.stanford.nlp.trees.EnglishGrammaticalRelations;
import edu.stanford.nlp.trees.GrammaticalRelation;
import edu.stanford.nlp.trees.TypedDependency;

public class _RcmodExtracter extends _Service {

	private _Service commonRcmodExtracter = null;
	
	public _Service getCommonRcmodExtracter() {
		return commonRcmodExtracter;
	}
	public void setCommonRcmodExtracter(_Service commonRcmodExtracter) {
		this.commonRcmodExtracter = commonRcmodExtracter;
	}

	@Override
	public Object service(Object... objects) throws Exception {
		// TODO Auto-generated method stub
		HashMap<?, ?> preprocessData = (HashMap<?, ?>) objects[0];
		__SentenceElements se = null;
		if ( objects.length >1) {
			se = (__SentenceElements) objects[1];
		} else {
			se = new __SentenceElements();
		}
		
		ArrayList<_RcmodTuple> RcmodTupleList = new ArrayList<_RcmodTuple>(8);
		Collection<?> tdl = (Collection<?>) preprocessData.get("tdl");
		for( Object obj : tdl) {
			TypedDependency TD = (TypedDependency) obj;
			GrammaticalRelation reln = TD.reln();
			if ( reln.equals(EnglishGrammaticalRelations.RELATIVE_CLAUSE_MODIFIER)) {
				/*
				 * 1.调用rcmod解析器
				 * 2.将结果添加到RcmodTupleList
				 */
				_RcmodTuple rt = (_RcmodTuple) this.commonRcmodExtracter.service(preprocessData, TD);
				if ( rt != null) RcmodTupleList.add(rt);
			}
		}
		
		se.RcmodTupleList.addAll(RcmodTupleList);
		return se;
	}
}
